package com.shengyijie.model.database.dataoperate;
 
 
 

import com.shengyijie.model.database.DBHandler;
import com.shengyijie.model.object.baseobject.User; 

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
 
public class MessageDB extends DBHandler{

	public static String TABLE_MESS="message";
	public static String COLUMN_ID="pro_id";
	public static String COLUMN_NAME="name";
	public static String COLUMN_MOBILE="monile";
	public static String COLUMN_EMAIL="ema";
	public static String COLUMN_ADDRESS="add";
	public static String COLUMN_CONTENT="content";   
	public MessageDB(Context ctx, String base_name, int version) {
		super(ctx, base_name, version);
	}

	public void createTable(){
		if(!isTableExits(TABLE_MESS)){
		   String sql = "create table "+MessageDB.TABLE_MESS+" (pro_id text,name text,monile text,ema text,add text,content text);";              
           db.execSQL(sql);
		}
	}
	public void deleteTable(){
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_MESS);
	}
	public long insertItem(String id,String type,String sessionid,String isRem,String add,String content) {
		deleteAllRecords();
		ContentValues initialValues = new ContentValues();
		initialValues.put(COLUMN_ID,id); 
		initialValues.put(COLUMN_NAME,type);
		initialValues.put(COLUMN_MOBILE,sessionid);
		initialValues.put(COLUMN_EMAIL,isRem);
		initialValues.put(COLUMN_ADDRESS,add);
		initialValues.put(COLUMN_CONTENT,content); 
		return db.insert(TABLE_MESS,null,initialValues);
	}
	
	public long insertItem(User user) {	 
//		if(isTableExits(TABLE_MESS)&&user!=null){ 
//			return insertItem(user.getUserID(),user.getUserType(),user.getSession_ID(),user.getIsRemember());
//		}
		    
		return -1;
	}
 

	public Cursor  fetchAllRecords(){
//		if(isTableExits(TABLE_MESS))
//		   return db.query(TABLE_MESS, new String[]{COLUMN_ID,COLUMN_Type,COLUMN_SESSIONID,COLUMN_IS_REMEMBER}, 
//		            null, null, null, null, null);
		return null;
    }

	public boolean deleteAllRecords() { 
		if(isTableExits(TABLE_MESS))
	        return db.delete(TABLE_MESS, null, null) > 0;
	     return false;

	}
	 

	 
	 
	
	public SQLiteDatabase getDB(){
		return this.db;
	}
}


